package com.harth.blemultiplatform.ble

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlin.time.Duration

interface ICentralManager: AutoCloseable {
    fun getPeripheralsById(ids: List<String>): List<IPeripheral>

    fun getPeripheralById(id: String): IPeripheral?
        = getPeripheralsById(listOf(id)).firstOrNull()
    fun scan(timeout: Duration = Duration.INFINITE): Flow<IScanResult>

    suspend fun connect(peripheral: IPeripheral)


    /**
     * A flow with the current state of the manager.
     */
    val state: StateFlow<State>

    /**
     * The possible states of a Bluetooth manager.
     */
    enum class State {
        /**
         * A state that indicates Bluetooth is currently powered off.
         */
        POWERED_OFF,

        /**
         * A state that indicates Bluetooth is currently powered on and available to use.
         */
        POWERED_ON,

        /**
         * A state that indicates the connection with the system service was momentarily lost.
         *
         * This state is not used on Android.
         */
        RESETTING,

        /**
         * The manager’s state is unknown.
         */
        UNKNOWN,

        /**
         * A state that indicates this device doesn't support the Bluetooth Low Energy.
         */
        UNSUPPORTED,
    }
}